package untils

import (
	"fmt"
	"strconv"
	"strings"
	"user_srv/handler/model"
)

// 解析uid
func MockToken(code string) (openid string, err error) {
	if !strings.HasPrefix(code, "MOCK_USER_") {
		return "", fmt.Errorf("invalid mock code")
	}
	return strings.TrimPrefix(code, "MOCK_USER_"), nil
}

// 返回用户真实信息
func MockUserInfo(uidStr string) (nick, avatar string, err error) {
	uid, _ := strconv.Atoi(uidStr)
	var u model.User
	if err = u.GetUserInfo(&model.User{Id: uint(uid)}); err != nil || u.Id == 0 {
		return "", "", fmt.Errorf("uid=%d not found", uid)
	}
	return u.Nickname, u.Avatar, nil
}
func MockOpenid(uidStr string) string {
	return fmt.Sprintf("MOCK_openid_%s", uidStr)
}
